<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=640px,user-scalable=no,target-densitydpi=device-dpi" />
		<link rel="stylesheet" href="../css/css.css" type="text/css" />
		<script type="text/javascript" src='../js/jquery.min.js'></script>
		<script type="text/javascript" src='../js/main_in.js'></script>
		<script type="text/javascript" src='../js/common.js'></script>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=TRd4GWTeP3j8W6Hcfn04DEqx6o5XRldw"></script>
		<title>运单录入</title>
		<script type="text/javascript">
			var uid = window.localStorage["uid"];
			var loginname = window.localStorage["lgname"];
			var cpid = window.localStorage["cpid"];
			var cpname = window.localStorage["cpname"];
			var ndid = window.localStorage["ndid"];
			var ndname = window.localStorage["ndname"];
			var d = 1;
			var eta = '';
			var distance_v = '';
			
			var lng1 = '';
			var lat1 = '';
			var lng2 = '';
			var lat1 = '';

			search_insure();    //  查保险信息

			$(function() {
				$("#search_customer_button").click(function() {
					search_customer();  //查发货客户
				});

				$("#search_address_button").click(function() {
					if(d == 1) {    //判断是否打开
						var CustomerID = $("#CustomerID").val();
						if(CustomerID == '') {
							return false;
						} else {
							search_address(CustomerID);  // 根据发货客户ID查收货单位
							$(".bgadd_s2").show();
						}
						d = 2;
					} else {
						if(d == 2) {
							$(".bgadd_s2").hide();
							d = 1;
						}
					}

				});

				$(".main_in_input_hide").click(function() {
					$(".main_in_input_hide").hide();
				});

				$("body").on("click", ".bgadd_s1 .main_in_input_hide_main", function() {
					var id = $(this).find('.main_in_input_hide_child').eq(0).html();
					var name = $(this).find('.main_in_input_hide_child').eq(1).html();
					var CityID = $(this).find('.main_in_input_hide_child').eq(2).html();
					var CityName = $(this).find('.main_in_input_hide_child').eq(3).html();
					var Address = $(this).find('.main_in_input_hide_child').eq(4).html();
					var Contact = $(this).find('.main_in_input_hide_child').eq(5).html();
					var ContactTel = $(this).find('.main_in_input_hide_child').eq(6).html();
					$("#CustomerName").val(name);
					$("#CustomerID").val(id);
					$("#cus_CityID").val(CityID);
					$("#cus_CityName").val(CityName);
					$("#cus_Address").val(Address);
					$("#cus_Contact").val(Contact);
					$("#cus_ContactTel").val(ContactTel);
				});

				$("body").on('click', ".bgadd_s2 .main_in_input_hide_main", function() {
					var name = $(this).find('.main_in_input_hide_child').eq(1).html();
					var id = $(this).find('.main_in_input_hide_child').eq(0).html();
					var CityID = $(this).find('.main_in_input_hide_child').eq(2).html();
					var CityName = $(this).find('.main_in_input_hide_child').eq(3).html();
					var Address = $(this).find('.main_in_input_hide_child').eq(4).html();
					var Contact = $(this).find('.main_in_input_hide_child').eq(5).html();
					var ContactTel = $(this).find('.main_in_input_hide_child').eq(6).html();
					$("#addressname").val(name);
					$("#addressid").val(id);
					$("#add_CityID").val(CityID);
					$("#add_CityName").val(CityName);
					$("#add_Address").val(Address);
					$("#add_Contact").val(Contact);
					$("#add_ContactTel").val(ContactTel);
					getaddr();
					$(".app_input_hide").hide();
				});
				
				$("body").on('click', ".bgadd_s3 .main_in_input_hide_main", function() {
                   var InquiryId = $(this).find('.main_in_input_hide_child').eq(1).html();
                   var id = $(this).find('.main_in_input_hide_child').eq(0).html();
                   var SNID = $(this).find('.main_in_input_hide_child').eq(2).html();
                   var SNScheFlightNo = $(this).find('.main_in_input_hide_child').eq(3).html();
                   var SNCorpName = $(this).find('.main_in_input_hide_child').eq(4).html();
                   $("#InquiryId").val(InquiryId);
                   $("#SNID").val(SNID);
                   $("#SNScheFlightNo").val(SNScheFlightNo);
                   $("#SNCorpName").val(SNCorpName);
                   
                   $(".app_input_hide").hide();
                });

				$("#Grade").change(function() {
					var grade_val = $(this).val();
					search_insure_grade(grade_val)
				});
				
				$("#Freight").on('input propertychange', function() {    //   运费变动算保费
					var grade_val = $("#Grade").val();

					var Freight = $(this).val();
					if(Freight > 50000) {
						alert("请检查输入的金额");
						$("#Freight").val('');
					}
					if(Freight <= 0) {
						alert("请检查输入的金额");
						$("#Freight").val('');
					}
					search_insure_grade(grade_val)
				});

			});

			function save_passenger() {   //   保存发货客户和收货单位
				var d = new Date();
				var str = '';
				str += d.getFullYear() + '-';
				str += d.getMonth() + 1 + '-';
				str += d.getDate() + '';
				str += ' ';
				str += d.getHours() + ':';
				str += d.getMinutes() + ':';
				str += d.getSeconds() + ''
				var CustomerName = $("#CustomerName").val();
				var cus_CityID = $("#cus_CityID").val();
				var cus_CityName = $("#cus_CityName").val();
				var cus_Address = $("#cus_Address").val();
				var cus_Contact = $("#cus_Contact").val();
				var cus_ContactTel = $("#cus_ContactTel").val();

				var addressname = $("#addressname").val();
				var add_CityID = $("#add_CityID").val();
				var add_CityName = $("#add_CityName").val();
				var add_Address = $("#add_Address").val();
				var add_Contact = $("#add_Contact").val();
				var add_ContactTel = $("#add_ContactTel").val();

				var body = {
					"Type": "10",
					"Name": CustomerName,
					"Tel": '',
					"NDID": ndid,
					"Email": "",
					"Fax": "",
					"Contact": cus_Contact,
					"ContactTel": cus_ContactTel,
					"Sales": "",
					"InvoiceType": "10",
					"Remark": "",
					"Img": "",
					"CPID": cpid,
					"Token": "22e8f734-dae9-494e-a743-4c4a64af4ce2",
					"Users": {
						"id": uid,
						"username": loginname,
						"cpid": cpid,
						"cpname": cpname,
						"ndid": ndid,
						"ndname": ndname,
						"cmid": ""
					},
					"CityID": cus_CityID,
					"CityName": cus_CityName,
					"Address": cus_Address,
					"CreateOn": str,
					"CreateBy": loginname
				}
				var cus_id_id = '';
				if(confirm("确认提交？")) {
					fade_out_pull("fade_out_loading");
					$.ajax({
						url: "http://api.unair.cn/api/CustomerBL",
						type: "POST",
						data: body,
						success: function(data) {
							data = eval("(" + data + ")");
							cus_id_id = data['ID'];
							var body2 = {
								"CityID": add_CityID,
								"CustomerID": cus_id_id,
								"CustomerName": CustomerName,
								"Warehouse": addressname,
								"Addr": add_Address,
								"Contact": add_Contact,
								"CityName": add_CityName,
								"ContactTel": add_ContactTel,
								"Remark": "",
								"Token": "22e8f734-dae9-494e-a743-4c4a64af4ce2",
								"Demand": "",
								"CPID": cpid,
								"NDID": ndid,
								"ReceiptDay": "",
								"DeliveryDay": "",
								"CreateBy": loginname,
								"CreateOn": str,
								"Type": 2
							}

							$.ajax({
								url: "http://api.unair.cn/api/AddressBL",
								type: "POST",
								data: body2,
								success: function(data) {
									alert("保存成功");
									fade_out_hide();
								},
								error: function(data) {
									alert("保存失败");
									fade_out_hide();
								}

							});
						},
						error: function(data) {
							alert("保存失败");
							fade_out_hide();
						}

					});

				};
			}

			function search_customer() {
				$(".bgadd_s1").find(".main_in_input_hide_main").remove();
				var where = " CreateBy = '" + loginname + "' and CPID='"+cpid+"'";
				var body = {
					"TableName": "Customer",
					"PKName": "ID",
					"PageSize": "999",
					'pageCurrent': 1,
					"where": where
				};

				$.ajax({
					url: "http://api.unair.cn/api/PagingQuery",
					type: "POST",
					data: body,
					success: function(data) {
						data = eval("(" + data.ResTable + ")");
						var item = '';
						$.each(data, function(k, v) {
							v.Name = typeof(v.Name) == 'undefined' ? '' : v.Name;
							v.Name = v.Name == null ? '' : v.Name;
							v.ContactTel = typeof(v.ContactTel) == 'undefined' ? '' : v.ContactTel;
							v.ContactTel = v.ContactTel == null ? '' : v.ContactTel;
							v.Contact = typeof(v.Contact) == 'undefined' ? '' : v.Contact;
							v.Contact = v.Contact == null ? '' : v.Contact;
							v.CityName = typeof(v.CityName) == 'undefined' ? '' : v.CityName;
							v.CityName = v.CityName == null ? '' : v.CityName;
							v.Address = typeof(v.Address) == 'undefined' ? '' : v.Address;
							v.Address = v.Address == null ? '' : v.Address;
							item += "<div class='main_in_input_hide_main'>" +
								"<div class='main_in_input_hide_child' style='display:none'>" + v.ID + "</div>" +
								"<div class='main_in_input_hide_child'>" + v.Name + "</div>" +
								"<div class='main_in_input_hide_child' style='display:none'>" + v.CityID + "</div>" +
								"<div class='main_in_input_hide_child' style='display:none'>" + v.CityName + "</div>" +
								"<div class='main_in_input_hide_child' style='display:none'>" + v.Address + "</div>" +
								"<div class='main_in_input_hide_child' style='display:none'>" + v.Contact + "</div>" +
								"<div class='main_in_input_hide_child' style='display:none'>" + v.ContactTel + "</div>" +
								"</div>";
						});
						$(".bgadd_s1").append(item);
					},
					error: function(data) {
						alert(data)
					}
				});
				$(".bgadd_s1").show();
			}

			function search_address(CustomerID) {
				$(".bgadd_s2").find(".main_in_input_hide_main").remove();
				var where = " CustomerID = '" + CustomerID + "' and Type = 2 ";
				var body = {
					"TableName": "Address",
					"PKName": "ID",
					"PageSize": "999",
					'pageCurrent': 1,
					"where": where
				};

				$.ajax({
					url: "http://api.unair.cn/api/PagingQuery",
					type: "POST",
					data: body,
					success: function(data) {
						data = eval("(" + data.ResTable + ")");
						var item = '';
						$.each(data, function(k, v) {
							v.Warehouse = typeof(v.Warehouse) == 'undefined' ? '' : v.Warehouse;
							v.Warehouse = v.Warehouse == null ? '' : v.Warehouse;
							v.CityName = typeof(v.CityName) == 'undefined' ? '' : v.CityName;
							v.CityName = v.CityName == null ? '' : v.CityName;
							v.Addr = typeof(v.Addr) == 'undefined' ? '' : v.Addr;
							v.Addr = v.Addr == null ? '' : v.Addr;
							v.Name = typeof(v.Name) == 'undefined' ? '' : v.Name;
							v.Name = v.Name == null ? '' : v.Name;
							v.ContactTel = typeof(v.ContactTel) == 'undefined' ? '' : v.ContactTel;
							v.ContactTel = v.ContactTel == null ? '' : v.ContactTel;
							v.Contact = typeof(v.Contact) == 'undefined' ? '' : v.Contact;
							v.Contact = v.Contact == null ? '' : v.Contact;
							item += "<div class='main_in_input_hide_main'>" +
								"<div class='main_in_input_hide_child' style='display:none'>" + v.ID + "</div>" +
								"<div class='main_in_input_hide_child'>" + v.Warehouse + "</div>" +
								"<div class='main_in_input_hide_child' style='display:none'>" + v.CityID + "</div>" +
								"<div class='main_in_input_hide_child' style='display:none'>" + v.CityName + "</div>" +
								"<div class='main_in_input_hide_child' style='display:none'>" + v.Addr + "</div>" +
								"<div class='main_in_input_hide_child' style='display:none'>" + v.Contact + "</div>" +
								"<div class='main_in_input_hide_child' style='display:none'>" + v.ContactTel + "</div>" +
								"</div>";
						});
						$(".bgadd_s2").append(item);
					},
					error: function(data) {
						alert(data)
					}
				});
			}

			function search_insure() {
				var body = {
					"TableName": "InsuranceMain",
					"PKName": "RID",
					"PageSize": "999",
					'pageCurrent': 1,
					"where": "CPID = '"+cpid+"'"
				};

				$.ajax({
					url: "http://api.unair.cn/api/PagingQuery",
					type: "POST",
					data: body,
					success: function(data) {
						data = eval("(" + data.ResTable + ")");
						var item = '';
						$.each(data, function(k, v) {
							item += "<option  value=" + v.Grade + ">" + v.Grade / 10000 + "万</option>";
						});
						$("#Grade").append(item)
					},
					error: function(data) {
						alert(data)
					}
				});
			}

			function search_insure_grade(grade_val) {
				var Freight = $("#Freight").val();
				
				
				var where = "CPID = '"+cpid+"'";
				if(grade_val != undefined) {
					where += " and Grade = " + grade_val;
				}
				var body = {
					"TableName": "InsuranceMain",
					"PKName": "RID",
					"PageSize": "999",
					'pageCurrent': 1,
					"where": where
				};
fade_out_pull("fade_out_loading");
				$.ajax({
					url: "http://api.unair.cn/api/PagingQuery",
					type: "POST",
					data: body,
					success: function(data) {
						data = eval("(" + data.ResTable + ")");
						var item = '';
						$.each(data, function(k, v) {
							$("#MinCharge1").val(v.MinCharge1);
							$("#MinCharge2").val(v.MinCharge2);
							$("#RobberyTheft").val(v.RobberyTheft);
							$("#DeductAmount").val(v.DeductAmount);
							$("#DeductRate").val(v.DeductRate);
							$("#Ratio1").val(v.Ratio1);
							$("#Ratio2").val(v.Ratio2); //费率
							$("#Rid").val(v.RID);
							
							if(cpid == "95961-44827" || cpid == "11583-47254"){
								if(distance_v < 1001){
									if(Freight > 9000){
										alert("运费不能超过9000");
										$("#Freight").val('');
										return false;
									}
									if(grade_val == 300000){
										$('#insurance_money_value').val(65);
									}
									if(grade_val == 1000000){
										$('#insurance_money_value').val(70);
									}
									if(grade_val == 2000000){
										$('#insurance_money_value').val(75);
									}
									if(grade_val == 3000000){
										$('#insurance_money_value').val(80);
									}
									if(grade_val == 5000000){
										$('#insurance_money_value').val(90);
									}
								}else if(distance_v < 1801){
									if(Freight > 16000){
										alert("运费不能超过16000");
										$("#Freight").val('');
										return false;
									}
									if(grade_val == 300000){
										$('#insurance_money_value').val(70);
									}
									if(grade_val == 1000000){
										$('#insurance_money_value').val(80);
									}
									if(grade_val == 2000000){
										$('#insurance_money_value').val(90);
									}
									if(grade_val == 3000000){
										$('#insurance_money_value').val(100);
									}
									if(grade_val == 5000000){
										$('#insurance_money_value').val(120);
									}
								}else if(distance_v < 2301){
									if(Freight > 19000){
										alert("运费不能超过19000");
										$("#Freight").val('');
										return false;
									}
									if(grade_val == 300000){
										$('#insurance_money_value').val(75);
									}
									if(grade_val == 1000000){
										$('#insurance_money_value').val(85);
									}
									if(grade_val == 2000000){
										$('#insurance_money_value').val(95);
									}
									if(grade_val == 3000000){
										$('#insurance_money_value').val(105);
									}
									if(grade_val == 5000000){
										$('#insurance_money_value').val(130);
									}
								}else if(distance_v < 3001){
									if(Freight > 22000){
										alert("运费不能超过22000");
										$("#Freight").val('');
										return false;
									}
									if(grade_val == 300000){
										$('#insurance_money_value').val(75);
									}
									if(grade_val == 1000000){
										$('#insurance_money_value').val(90);
									}
									if(grade_val == 2000000){
										$('#insurance_money_value').val(100);
									}
									if(grade_val == 3000000){
										$('#insurance_money_value').val(115);
									}
									if(grade_val == 5000000){
										$('#insurance_money_value').val(140);
									}
								}else if(distance_v < 3501){
									if(Freight > 26000){
										alert("运费不能超过26000");
										$("#Freight").val('');
										return false;
									}
									if(grade_val == 300000){
										$('#insurance_money_value').val(80);
									}
									if(grade_val == 1000000){
										$('#insurance_money_value').val(95);
									}
									if(grade_val == 2000000){
										$('#insurance_money_value').val(110);
									}
									if(grade_val == 3000000){
										$('#insurance_money_value').val(125);
									}
									if(grade_val == 5000000){
										$('#insurance_money_value').val(155);
									}
								}else if(distance_v < 4001){
									if(Freight > 28000){
										alert("运费不能超过28000");
										$("#Freight").val('');
										return false;
									}
									if(grade_val == 300000){
										$('#insurance_money_value').val(85);
									}
									if(grade_val == 1000000){
										$('#insurance_money_value').val(100);
									}
									if(grade_val == 2000000){
										$('#insurance_money_value').val(115);
									}
									if(grade_val == 3000000){
										$('#insurance_money_value').val(130);
									}
									if(grade_val == 5000000){
										$('#insurance_money_value').val(165);
									}
								}
							}else{
								var money2 = ((Freight * 100) * (v.Ratio2 * 100)) / 10000;
								if(money2 > v.MinCharge2) {
									$('#insurance_money_value').val(money2);
								} else {
									$('#insurance_money_value').val(v.MinCharge2);
								}
								
							}
							///算成本
								var money1 = ((Freight * 100) * (v.Ratio1 * 100)) / 10000;
								if(money1 > v.MinCharge1) {
									$('#insurance_money_value1').val(money1);
								} else {
									$('#insurance_money_value1').val(v.MinCharge1);
								}
							
							
							
								

						});
fade_out_hide();
					},
					error: function(data) {
						fade_out_hide();
						alert(data)
					}
				});
			}

			function doadd() {
				var d = new Date();
				var str = '';
				str += d.getFullYear() + '-';
				str += d.getMonth() + 1 + '-';
				str += d.getDate() + '';
				str += ' ';
				str += d.getHours() + ':';
				str += d.getMinutes() + ':';
				str += d.getSeconds() + '';

				var CustomerName = $("#CustomerName").val();
				var CustomerID = $("#CustomerID").val();
				var cus_CityID = $("#cus_CityID").val();
				var cus_CityName = $("#cus_CityName").val();
				var cus_Address = $("#cus_Address").val();
				var cus_Contact = $("#cus_Contact").val();
				var cus_ContactTel = $("#cus_ContactTel").val();

				var addressname = $("#addressname").val();
				var addressid = $("#addressid").val();
				var add_CityID = $("#add_CityID").val();
				var add_CityName = $("#add_CityName").val();
				var add_Address = $("#add_Address").val();
				var add_Contact = $("#add_Contact").val();
				var add_ContactTel = $("#add_ContactTel").val();
				var InquiryId = $("#InquiryId").val();
				var SNID = $("#SNID").val();
				var SNCorpName = $("#SNCorpName").val();
				var SNScheFlightNo = $("#SNScheFlightNo").val();

				var FreightName = $("#FreightName").val();
				var Number = $("#Number").val();
				var Freight = $("#Freight").val();

				var MinCharge1 = $("#MinCharge1").val();
				var MinCharge2 = $("#MinCharge2").val();
				var RobberyTheft = $("#RobberyTheft").val();
				var DeductAmount = $("#DeductAmount").val();
				var DeductRate = $("#DeductRate").val();
				var Ratio1 = $("#Ratio1").val();
				var Ratio2 = $("#Ratio2").val(); //费率
				var Rid = $("#Rid").val();
				var insurance_money_value = $('#insurance_money_value').val();
				var insurance_money_value1 = $("#insurance_money_value1").val();
				var Grade = $("#Grade").val();
				
				if(eta == '') {
					alert("时间计算错误");
					return;
				}
				
				if(distance_v == '') {
					alert("里程不能为空");
					return;
				}
				
				if(CustomerName == '') {
					alert("发货方不能为空");
					return;
				}
				if(cus_CityName == '') {
					alert("发货城市不能为空");
					return;
				}
				if(cus_Address == '') {
					alert("发货方详细地址不能为空");
					return;
				}
				if(cus_Contact == '') {
					alert("发货方联系人不能为空");
					return;
				}
				if(cus_ContactTel == '') {
					alert("发货方电话不能为空");
					return;
				}

				if(addressname == '') {
					alert("收货方不能为空");
					return;
				}
				if(add_CityName == '') {
					alert("收货城市不能为空");
					return;
				}
				if(add_Address == '') {
					alert("收货方详细地址不能为空");
					return;
				}
				if(add_Contact == '') {
					alert("收货方联系人不能为空");
					return;
				}
				if(add_ContactTel == '') {
					alert("收货方电话不能为空");
					return;
				}

				if(InquiryId == '') {
					alert("车牌号码不能为空");
					return;
				}

				if(SNID == '') {
					alert("车挂号不能为空");
					return;
				}

				if(SNCorpName == '') {
					alert("司机电话不能为空");
					return;
				}

				if(SNScheFlightNo == '') {
					alert("司机姓名不能为空");
					return;
				}

				if(FreightName == '') {
					alert("货物名称不能为空");
					return;
				}
				if(Number == '') {
					alert("件数不能为空");
					return;
				}
				if(Freight == '') {
					alert("运费不能为空");
					return;
				}

				if(Freight == 0) {
					alert("运费不能为0");
					return;
				}

				if(insurance_money_value == '') {
					alert("服务费不能为空");
					return;
				}

				if(confirm("确认提交？")) {
					fade_out_pull("fade_out_loading");

					var dd = new Date();
					var str2 = '';
					str2 += dd.getFullYear();
					str2 += dd.getMonth() + 1;
					str2 += dd.getDate();
					str2 += dd.getHours();
					str2 += dd.getMinutes();
					str2 += dd.getSeconds();
					str2 += parseInt(899 * Math.random() + 100);

					var body = {
						"APID": str2,
						"Consignor": CustomerName,
						"FromAreaID": cus_CityID,
						"FromArea": cus_CityName,
						"FromAddress": cus_Address,
						"Contact1": cus_Contact,
						"ContactTel1": cus_ContactTel,
						"Consignee": addressname,
						"ToAreaID": add_CityID,
						"ToArea": add_CityName,
						"ToAddress": add_Address,
						"Contact2": add_Contact,
						"ContactTel2": add_ContactTel,
						"PlateNo": InquiryId,
						"CHEGUAHAO": SNID,
						"DriverName": SNScheFlightNo,
						"DriverMobile": SNCorpName,
						"ItemName": FreightName,
						"ItemCount": Number,
						"Freight": Freight,
						"ItemPrice": Grade,
						"Insurance1": insurance_money_value1,
						"Insurance2": insurance_money_value,
						"MinCharge1": MinCharge1,
						"MinCharge2": MinCharge2,
						"RobberyTheft": RobberyTheft,
						"DeductAmount": DeductAmount,
						"DeductRate": DeductRate,
						"Ratio1": Ratio1,
						"Ratio2": Ratio2,
						"RidOfInsuranceMain": Rid,
						"CreateOn": str,
						"BGID": '',
						"UserID": uid,
						'LoginName': loginname,
						"CPID": cpid,
						"CPName":cpname,
						"NDID": ndid,
						"NDName" : ndname,
						"Distance" : distance_v,
						"ETA" : eta,
						"State" : 0
					}
					$.ajax({
						url: "http://api.unair.cn/api/AliPayBL",
						type: "POST",
						data: body,
						success: function(data) {
							if(data['RID'] > 0) {
								clicked("payment.html?order_id=" + str2 + "&money_val=" + insurance_money_value + "&order_money=" + insurance_money_value);
							} else {
								alert("提交失败");
							}
						},
						error: function(data) {
							alert(data);
						}
					});

				}
			}
			
function car_search(){
    $(".bgadd_s3").find(".main_in_input_hide_main").remove();
    $.ajax({
                    url: "http://api.unair.cn/api/DriverBL?userID=" + uid +"&driverId=0",
                    type: "GET",
                    data: {},
                    success: function(data) {
                        var item = '';
                        $.each(data, function(k, v) {
                            v.PlateNo2 = typeof (v.PlateNo2) == 'undefined' ? '' : v.PlateNo2;
                            v.PlateNo2 = v.PlateNo2 == null ? '' : v.PlateNo2;
                            v.DriverName = typeof (v.DriverName) == 'undefined' ? '' : v.DriverName;
                            v.DriverName = v.DriverName == null ? '' : v.DriverName;
                            v.Mobile = typeof (v.Mobile) == 'undefined' ? '' : v.Mobile;
                            v.Mobile = v.Mobile == null ? '' : v.Mobile;
                            item += "<div class='main_in_input_hide_main'>" +
                                        "<div class='main_in_input_hide_child' style='display:none'>" + v.DriverID + "</div>" +
                                        "<div class='main_in_input_hide_child'>" + v.PlateNo + "</div>" +
                                        "<div class='main_in_input_hide_child' style='display:none'>" + v.PlateNo2 + "</div>" +
                                        "<div class='main_in_input_hide_child' style='display:none'>" + v.DriverName + "</div>" +
                                        "<div class='main_in_input_hide_child' style='display:none'>" + v.Mobile + "</div>" +
                                    "</div>";
                        });
                        $(".bgadd_s3").append(item);
                    },
                    error: function(data) {
//                        alert(data)
                    }
                });
    $(".bgadd_s3").show();
}



	function getaddr(){
		var city1 = $("#cus_CityName").val();
		var address1 = $("#cus_Address").val();
		var city2 = $("#add_CityName").val();
		var address2 = $("#add_Address").val();
		getjw(city1 + address1,city2+address2);
	}
	
	function getjw(address1,address2){
//		baidu_jw('上海',1);
//		baidu_jw('北京',2);
		addr1(address1,address2);
//								var t=setInterval(function(e){
//									get_distance()
//									clearInterval(t);
//								},3000);
	}
	
	
	function addr1(address1,address2){
		var checkUrl = "http://api.map.baidu.com/geocoder/v2/?address="+address1+"&output=json&ak=TRd4GWTeP3j8W6Hcfn04DEqx6o5XRldw";
		var xhr=new XMLHttpRequest();
	    xhr.onreadystatechange=function(){
	    	
	        switch(xhr.readyState){
	            case 4:
		            data = eval("(" + xhr.response + ")");
					lng1 = data['result']['location']['lng'];
	            	lat1 = data['result']['location']['lat'];
	            	addr2(address2)
	            break;
	            default:
	            break;
	        }
	    }
	    xhr.open('GET',checkUrl);
	    xhr.send();
	}
	
	function addr2(address2){
		var checkUrl = "http://api.map.baidu.com/geocoder/v2/?address="+address2+"&output=json&ak=TRd4GWTeP3j8W6Hcfn04DEqx6o5XRldw";
		var xhr=new XMLHttpRequest();
	    xhr.onreadystatechange=function(){
	    	
	        switch(xhr.readyState){
	            case 4:
		            data = eval("(" + xhr.response + ")");
					lng2 = data['result']['location']['lng'];
	            	lat2 = data['result']['location']['lat'];
	            	get_distance()
	            break;
	            default:
	            break;
	        }
	    }
	    xhr.open('GET',checkUrl);
	    xhr.send();
	}
	
	// 百度地图API功能
	function get_distance(){
		if(lng1 !='' && lng2 != ''){
			var map = new BMap.Map("allmap");
			var pointA = new BMap.Point(lng1,lat1);  // 创建点坐标A
			var pointB = new BMap.Point(lng2,lat2);  // 创建点坐标B
			
			distance_v = (map.getDistance(pointA,pointB) / 1000 * 1.2).toFixed(2);
			$("#distance").val(distance_v+'公里');
			var eta_t = (distance_v/70).toFixed(2);
			var timestamp = Date.parse(new Date());
			var time = new Date(timestamp*1 + eta_t*3600000);
			eta = time.toLocaleDateString().replace(/\//g, "-") + " " + time.toTimeString().substr(0, 8);
					var grade_val = $("#Grade").val();
					search_insure_grade(grade_val);
		}
	}
		</script>
	</head>

	<body>
		<div class="app_head">
			<div class="app_prev" onclick="clicked('../index.html')"><img src="../img/arrow.png" /></div>
			<div class="app_head_text">开具运单</div>
			<div class="app_prev"></div>
		</div>
		<div class="app_body">
			<div class="main_in_input">
				<div class="main_in_input_text_left">发货方：</div>
				<div style="width: 40%;" class="main_in_input_input_right"><input type="text" id="CustomerName" value="" /></div>
				<input type="hidden" name="customerid" id="CustomerID" />
				<div class="main_in_input_button_s2" id="search_customer_button">请选择</div>
			</div>
			<div class="main_in_input_hide bgadd_s1">

			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">发货城市：</div>
				<div class="main_in_input_input_right"><input type="text" class="select_city" id="cus_CityName" value="" readonly="true" /></div>
				<input type="hidden" class="select_city_id" name="cus_CityID" id="cus_CityID" />
			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">详细地址：</div>
				<div class="main_in_input_input_right"><input type="text" id="cus_Address" value="" onblur="getaddr()" /></div>
			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">发货联系人：</div>
				<div class="main_in_input_input_right"><input type="text" id="cus_Contact" value="" /></div>
			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">发货人电话：</div>
				<div class="main_in_input_input_right"><input type="text" id="cus_ContactTel" value="" /></div>
			</div>

			<div class="main_in_input">
				<div class="main_in_input_text_left">收货方：</div>
				<div style="width: 40%;" class="main_in_input_input_right"><input type="text" id="addressname" value="" /></div>
				<input type="hidden" name="addressid" id="addressid" />
				<div class="main_in_input_button_s2" id="search_address_button">请选择</div>
			</div>
			<div class="main_in_input_hide bgadd_s2">

			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">收货城市：</div>
				<div class="main_in_input_input_right"><input type="text" class="select_city" id="add_CityName" value="" readonly="true" /></div>
				<input type="hidden" class="select_city_id" name="cus_CityID" id="add_CityID" />
			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">详细地址：</div>
				<div class="main_in_input_input_right"><input type="text" id="add_Address" value="" onblur="getaddr()" /></div>
			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">收货联系人：</div>
				<div class="main_in_input_input_right"><input type="text" id="add_Contact" value="" /></div>
			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">收货人电话：</div>
				<div class="main_in_input_input_right"><input type="text" id="add_ContactTel" value="" /></div>
			</div>
			<div style="border: none;" class="main_in_input">
				<div class="main_in_input_text_left"></div>
				<div style="width: 35%;" class="main_in_input_input_right"></div>
				<div style="width: 27%" class="main_in_input_button_s2" onclick="save_passenger()">保存资料</div>
			</div>

			<div class="main_in_input">
				<div class="main_in_input_text_left">里程：</div>
				<div class="main_in_input_input_right"><input type="text" id="distance" value="" /></div>
			</div>
			<div class="main_in_input">
                <div class="main_in_input_text_left">车牌号：</div>
                <div style="width: 40%;" class="main_in_input_input_right"><input type="text" id="InquiryId" value="" /></div>
                <div class="main_in_input_button_s2" id="search_car_button" onclick="car_search()">请选择</div>
            </div>
            <div class="main_in_input_hide bgadd_s3"></div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">车挂号：</div>
				<div class="main_in_input_input_right"><input type="text" id="SNID" value="" /></div>
			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">司机姓名：</div>
				<div class="main_in_input_input_right"><input type="text" id="SNScheFlightNo" value="" /></div>
			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">司机电话：</div>
				<div class="main_in_input_input_right"><input type="text" id="SNCorpName" value="" /></div>
			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">货物名称：</div>
				<div class="main_in_input_input_right"><input type="text" id="FreightName" value="" /></div>
			</div>
			<!--<div class="main_in_input">
				<div class="main_in_input_text_left">货物件数：</div>
				<div class="main_in_input_input_right"><input type="text" class="checkfloat" floatlength="2" id="Number" value="1" /></div>
			</div>-->
			<div class="main_in_input">
				<div class="main_in_input_text_left">运费：</div>
				<div class="main_in_input_input_right"><input type="text" class="checkfloat" floatlength="2" id="Freight" value="" /></div>
			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">货物估值：</div>
				<div class="main_in_input_input_right">
					<select class='app_input_text' name='Grade' id='Grade'>

					</select>
				</div>
			</div>

			<div class="main_in_input disnone">
				<div class="main_in_input_text_left">信息服务费1：</div>
				<div class="main_in_input_input_right"><input type="text" id="insurance_money_value1" value="" /></div>
			</div>
			<div class="main_in_input">
				<div class="main_in_input_text_left">信息服务费：</div>
				<div class="main_in_input_input_right"><input type="text" id="insurance_money_value" value="" readonly /></div>
			</div>
			<div class="main_in_input disnone">
				<div class="main_in_input_text_left">最低保费1：</div>
				<div class="main_in_input_input_right"><input type="text" id="MinCharge1" value="" /></div>
			</div>
			<div class="main_in_input disnone">
				<div class="main_in_input_text_left">最低保费2：</div>
				<div class="main_in_input_input_right"><input type="text" id="MinCharge2" value="" /></div>
			</div>
			<div class="main_in_input disnone">
				<div class="main_in_input_text_left">盗保限额：</div>
				<div class="main_in_input_input_right"><input type="text" id="RobberyTheft" value="" /></div>
			</div>
			<div class="main_in_input disnone">
				<div class="main_in_input_text_left">：</div>
				<div class="main_in_input_input_right"><input type="text" id="DeductAmount" value="" /></div>
			</div>
			<div class="main_in_input disnone">
				<div class="main_in_input_text_left">：</div>
				<div class="main_in_input_input_right"><input type="text" id="DeductRate" value="" /></div>
			</div>
			<div class="main_in_input disnone">
				<div class="main_in_input_text_left">费率1：</div>
				<div class="main_in_input_input_right"><input type="text" id="Ratio1" value="" /></div>
			</div>
			<div class="main_in_input disnone">
				<div class="main_in_input_text_left">费率2：</div>
				<div class="main_in_input_input_right"><input type="text" id="Ratio2" value="" /></div>
			</div>
			<div class="main_in_input disnone">
				<div class="main_in_input_text_left">RID：</div>
				<div class="main_in_input_input_right"><input type="text" id="Rid" value="" /></div>
			</div>
			<div style="background: #fff;width: 100%;height: 100px;">
				<div class="bg_submit" onclick="doadd()">提&nbsp;交</div>
				<div class="bg_back_class" onclick="back()">取&nbsp;消</div>
			</div>

		</div>

		<div class="outside_pull"></div>
		<img src="../img/loading.gif" class="fade_out_img" id="fade_out_loading" />
	</body>
<script type="text/javascript">
	
				
	
</script>
</html>